package com.lagou.rabbitmq.handler;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

import java.io.Serializable;

/**
 * @className: StockMessage
 * @auther: Jerry
 * @date: 2021/3/18 9:26
 * @desctiption: TODO
 * @version: 1.0
 */
public class StockMessage implements Serializable{
    private static final long serialVersionUID = 3350887386269934948L;
    private Long goodsId;
    private int stock;
    private String action;
    public static final String ADD_STOCK = "0";
    public static final String REDUCE_STOCK = "1";

    public StockMessage(Long goodsId, int stock, String action) {
        this.goodsId = goodsId;
        this.stock = stock;
        this.action = action;
    }
    public byte[] toByteArray() {
        ByteBuf buf = Unpooled.buffer(32);
        buf.writeLong(getGoodsId());
        buf.writeInt(getStock());
        buf.writeBytes(getAction().getBytes());
        return buf.array();
    }

    public Long getGoodsId() {
        return goodsId;
    }

    public void setGoodsId(Long goodsId) {
        this.goodsId = goodsId;
    }

    public int getStock() {
        return stock;
    }

    public void setStock(int stock) {
        this.stock = stock;
    }

    public String getAction() {
        return action;
    }

    public void setAction(String action) {
        this.action = action;
    }

    @Override
    public String toString() {
        return "StockMessage{" +
                "goodsId=" + goodsId +
                ", stock=" + stock +
                ", action='" + action + '\'' +
                '}';
    }
}
